package com.zzuli.practice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzuli.practice.entity.History;
import com.zzuli.practice.entity.Repairman;
import com.zzuli.practice.entity.Result;
import com.zzuli.practice.mapper.HistoryMapper;
import com.zzuli.practice.service.impl.HistoryService;
import com.zzuli.practice.util.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/history")
public class HistoryController implements Constant {

    @Autowired
    private HistoryService historyService;

    @RequestMapping(value = {"/getHistoryList/{pageIndex}", "/getHistoryList"}, method = RequestMethod.POST)
    public Result getHistoryListByName(@PathVariable("pageIndex") Integer pageIndex, String username){

        Result result = new Result();

        if (username == null){
            result.setStatusCode(FAILURE);
            result.setMessage("您还未登录");
            return result;
        }

        try{
            IPage<History> iPage = historyService.historyIPage(pageIndex, username);
            if (iPage != null && iPage.getSize() > 0){
                result.setStatusCode(SUCCESS);
                result.setMessage("success");
                result.setData(iPage);
            } else {
                result.setStatusCode(UNFIND);
                result.setMessage("没有数据");
            }
        } catch (Exception e){
            result.setStatusCode(UNFIND);
            result.setMessage("系统异常");
            e.printStackTrace();
        }
        return result;
    }

}
